package com.bluefuture.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bluefuture.modules.app.form.ComplaintForm;
import com.bluefuture.modules.sys.security.user.SecurityUser;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bluefuture.common.utils.PageUtils;
import com.bluefuture.common.utils.Query;

import com.bluefuture.modules.app.dao.UserComplaintDao;
import com.bluefuture.modules.app.entity.UserComplaintEntity;
import com.bluefuture.modules.app.service.UserComplaintService;


@Service("userComplaintService")
public class UserComplaintServiceImpl extends ServiceImpl<UserComplaintDao, UserComplaintEntity> implements UserComplaintService {

    @Override
    public void saveComplaint(ComplaintForm complaintForm) {
        UserComplaintEntity entity = new UserComplaintEntity();
        entity.setUserId(SecurityUser.getUserId());
        entity.setComplaintUserId(complaintForm.getComplaintUserId());
        entity.setComplaintType(complaintForm.getComplaintType());
        entity.setComplaintContent(complaintForm.getComplaintContent());
        save(entity);

    }

    @Override
    public List<Long> getBlockUserIds(Long userId) {
        LambdaQueryWrapper<UserComplaintEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserComplaintEntity::getUserId,userId)
                .eq(UserComplaintEntity::getComplaintType,1);
        List<Long> returnList = list(wrapper).stream().map(e -> e.getComplaintUserId()).collect(Collectors.toList());
        return returnList;
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<UserComplaintEntity> page = this.page(
                new Query<UserComplaintEntity>().getPage(params),
                new QueryWrapper<UserComplaintEntity>()
        );

        return new PageUtils(page);
    }

}